package org.geekbang.thinking.in.spring.bean.definition;

import org.geekbang.thinking.in.spring.bean.factory.UserFactoryBean;
import org.geekbang.thinking.in.spring.ioc.overview.domain.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Bean 实例化实例
 *
 * @author <a href="mailto:hushengjin1993@gmail.com>Hu Shengjin</a>
 * @since
 */
public class BeanInstantiationDemo {

    public static void main(String[] args) {
        // 配置 XML 文件
        // 启动 Spring 应用上下文
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/bean-creation-context.xml");

        User byStaticUser = beanFactory.getBean("user-by-static-method", User.class);
        User byInstanceUser = beanFactory.getBean("user-by-instance-method", User.class);
        User byFactoryUser = beanFactory.getBean("user-by-factory-bean", User.class);

        System.out.println(byStaticUser);
        System.out.println(byInstanceUser);
        System.out.println(byFactoryUser);

        System.out.println(byInstanceUser == byStaticUser);
        System.out.println(byFactoryUser == byStaticUser);
    }

}
